#ifndef AAAPACK_H
#define AAAPACK_H
#include <stdint.h>
#include "AAAAttrbute.h"
#include <vector>
#include <array>


//方便协议内存操作的结构体
#pragma pack( push )
#pragma pack( 1 )
struct SMsgPack
{
    uint8_t codePlace;
    uint8_t identifier;
    uint16_t length;
    uint8_t authenticatior[16];
   // char AttrPlace;						// 属性开始的地址
};
#pragma pack( pop )


enum class EMsgCode : uint8_t
{
    CODE_NONE = 0,
    ACCESS_REQUEST = 1,	// 接入请求报文
    ACCESS_ACCEPT = 2,		//	接入成功回应报文
};

class AAAPack
{
public:
    AAAPack() = default;
    ~AAAPack() = default;

    std::string scret() const;
    void setScret(const std::string &scret);

    EMsgCode code() const;
    void setCode(const EMsgCode &code);

    void addAttr(EAttrType type ,const void *data, uint16_t dataLen);

    uint8_t identifier() const;
    void setIdentifier(const uint8_t &identifier);

    //多于16位的无效，小于16位的补零

    std::array<uint8_t, 16> authenticator() const;
    void setAuthenticator(const std::array<uint8_t, 16> &authenticator);

    bool pack( uint8_t*& data, uint8_t& dataLen );
private:
    std::string _scret = "";										///< 共享秘钥
    EMsgCode _code = EMsgCode::CODE_NONE;
    uint8_t _identifier = 0;								///< 标识符,可使用随机数函数生成
    uint16_t _length = sizeof( SMsgPack );		///< 长度
    std::array<uint8_t,16> _authenticator;	///< 认证字
    std::vector<AAAAttrbute> _attrs;				///< 属性数组
    std::shared_ptr<uint8_t> _pbuf;				///< 存放打包好的数据
};

#endif // AAAPACK_H
